package org.jshand.reproduction;

import java.awt.BorderLayout;
import java.awt.FlowLayout;
import java.awt.Frame;
import java.awt.Label;
import java.awt.Menu;
import java.awt.MenuBar;
import java.awt.MenuItem;
import java.awt.TextField;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.ItemEvent;
import java.awt.event.ItemListener;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.io.UnsupportedEncodingException;

import javax.swing.BorderFactory;
import javax.swing.JComboBox;
import javax.swing.JToolBar;

public class Demo1 {

	public static void main(String[] args) {
		
		
		Frame frame = new Frame();
		frame.setTitle("演示窗体");
		frame.setBounds(280,260, 400, 340);
		
		MenuBar mb = new MenuBar();
		Menu fileMenu = new Menu("文件");
		fileMenu.add(new MenuItem("打开"));
		mb.add(fileMenu);
		frame.setMenuBar(mb);
		
		JToolBar jtoolbar = new JToolBar();
		jtoolbar.setLayout(new FlowLayout());
		jtoolbar.add(new Label("请输入:"));
		
		jtoolbar.add(new TextField(10));
		
		String[] selectOption = {"下拉选一","下拉选2"};
		final JComboBox select = new JComboBox(selectOption);
//		select.add(new Label("下拉选1"));
//		select.add(new Label("下拉选2"));
//		select.addItemListener(new ItemListener() {
//			
//			@Override
//			public void itemStateChanged(ItemEvent e) {
//				System.out.println(select.getEditor().getItem());;
//			}
//		});
		
		
//		 select.addItemListener(new ItemListener() {
//			
//			@Override
//			public void itemStateChanged(ItemEvent e) {
//				System.out.println("abccc"+e.getStateChange());
//			}
//		});  
		
		
		select.addActionListener(new ActionListener() {
			
			@Override
			public void actionPerformed(ActionEvent e) {
				System.out.println(e.getSource());
				try {
					System.out.println( new String(select.getSelectedObjects()[0].toString().getBytes("utf-8"),"GB18030"));
				} catch (UnsupportedEncodingException e1) {
					e1.printStackTrace();
				}
			}
		});
//		 select.setMaximumRowCount(3);;  
		
//		select.add
		jtoolbar.add(select);
		
		frame.add(jtoolbar,BorderLayout.NORTH);
		frame.addWindowListener(new WindowAdapter() {

			@Override
			public void windowClosed(WindowEvent e) {
				System.out.println("窗口关闭");
			}

			@Override
			public void windowClosing(WindowEvent e) {
				System.out.println("ing....");
				System.exit(0);
			}

			@Override
			public void windowLostFocus(WindowEvent e) {
				// TODO Auto-generated method stub
				System.out
						.println("Demo1.main(...).new WindowAdapter() {...}.windowLostFocus()");
			}
			
		});
		
		frame.setVisible(true);
		
//		frame
	}
	
	
	
}
